//
//  KBMusicListTwoCell.m
//  喜马拉雅改良版框架
//
//  Created by dllo on 15/12/30.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "KBMusicListTwoCell.h"

@implementation KBMusicListTwoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self)
    {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    // 图片
    _coverSmall = [[UIImageView alloc] init];
    //裁掉边框
    _coverSmall.layer.masksToBounds = YES;
    //设置半径
    _coverSmall.layer.cornerRadius = 40;
    [self.contentView addSubview:_coverSmall];
    [_coverSmall mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(12);
        make.size.mas_equalTo(CGSizeMake(80, 80));
        
    }];
    
    // 标题
    _title = [[UILabel alloc] init];
    _title.font = [UIFont systemFontOfSize:16];
    _title.numberOfLines = 2;
    [self.contentView addSubview:_title];
    [_title mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(_coverSmall.mas_top);
        make.left.equalTo(_coverSmall.mas_right).offset(4);
        make.width.mas_equalTo(210);
        make.height.mas_equalTo(40);
        
    }];
    // 内容
    _nickname = [[UILabel alloc] init];
    _nickname.font = [UIFont systemFontOfSize:14];
    _nickname.textColor = [UIColor colorWithRed:0.31 green:0.31 blue:0.31 alpha:1];
    [self.contentView addSubview:_nickname];
    [_nickname mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(_title.mas_bottom);
        make.left.equalTo(_title.mas_left).offset(5);
        make.width.mas_equalTo(235);
        make.height.mas_equalTo(22);
        
    }];
    
    // 播放次数(图)
    UIImageView *playtime = [[UIImageView alloc] init];
    playtime.image = [UIImage imageNamed:@"sound_playtimes@2x.png"];
    [self.contentView addSubview:playtime];
    [playtime mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_nickname.mas_bottom).offset(5);
        make.left.mas_equalTo(_nickname.mas_left).offset(3);
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(10);
    }];
    
    // 播放次数
    _playsCounts = [[UILabel alloc] init];
    _playsCounts.font = [UIFont systemFontOfSize:13];
    _playsCounts.textColor = [UIColor colorWithRed:0.64 green:0.64 blue:0.64 alpha:1];
    [self.contentView addSubview:_playsCounts];
    [_playsCounts mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(playtime.mas_top).offset(-5);
        make.left.mas_equalTo(playtime.mas_right).offset(5);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(20);
        
    }];
    // 时长 (图)
    UIImageView *setImage = [[UIImageView alloc] init];
    setImage.image = [UIImage imageNamed:@"iconfont-biao.png"];
    [self.contentView addSubview:setImage];
    
    [setImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(playtime.mas_top);
        make.left.mas_equalTo(_playsCounts.mas_right).offset(10);
        make.width.mas_equalTo(11);
        make.height.mas_equalTo(11);
    }];
    
    // 时长
    _turation = [[UILabel alloc] init];
    _turation.font = [UIFont systemFontOfSize:13];
    _turation.textColor = [UIColor colorWithRed:0.64 green:0.64 blue:0.64 alpha:1];
    [self.contentView addSubview:_turation];
    [_turation mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(_playsCounts.mas_top);
        make.left.mas_equalTo(setImage.mas_right).offset(5);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(20);
        
    }];
    
    // ?个月前
    _createdAt = [[UILabel alloc] init];
    _createdAt.font = [UIFont systemFontOfSize:13];
    _createdAt.textAlignment = NSTextAlignmentRight;
    _createdAt.textColor = [UIColor colorWithRed:0.31 green:0.31 blue:0.31 alpha:1];
    [self.contentView addSubview:_createdAt];
    [_createdAt mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_title.mas_top);
        make.right.mas_equalTo(10);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(20);
        
    }];
    
}

- (void)setModel:(KBMusicListModel *)model
{
    _title.text = model.title;
    NSURL *url = [NSURL URLWithString:model.coverSmall];
    [_coverSmall sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:ImagePlaceHolder]];
    _nickname.text = [NSString stringWithFormat:@"by %@", model.nickname];
    NSLog(@"nickname = %@", model.nickname);
    
    // 播放次数
    CGFloat number = model.playsCounts /10000.0;
    _playsCounts.text = [NSString stringWithFormat:@"%.1f万", number];
    
    // 播放时长
    _turation.text = [NSString stringWithFormat:@"%ld:%ld", (NSInteger)model.duration/60, (NSInteger)model.duration%60];
    
    // 时间戳
    NSInteger num = model.createdAt.integerValue;
    NSString *string = [LXTimeTool getDateWithUpdatedAt:num];
    _createdAt.text = string;
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
